<?php session_start();  ?>
<?php
require_once('Connections/tecno.php'); 

mysql_select_db($database_tecno, $tecno);

$prestamosAll = "SELECT (SUM(monto) + SUM(abono)) as total, SUM(abono) as cobrado, SUM(monto) as porcobrar FROM detallescliente WHERE tipo=3";
$query = mysql_query($prestamosAll, $tecno) or die(mysql_error());
$row_prestamosAll= mysql_fetch_assoc($query);
$totalRows_prestamosAll = mysql_num_rows($query);

$prestamosTotal = "SELECT SUM(monto) as totalCuotasPagadas FROM detallescliente WHERE tipo=2 AND status=1";
$query = mysql_query($prestamosTotal, $tecno) or die(mysql_error());
$row_prestamosTotal= mysql_fetch_assoc($query);
$totalRows_prestamosTotal = mysql_num_rows($query);


$prestamosTotal2 = "SELECT SUM(abono) as totalCuotasAbonadas FROM detallescliente WHERE tipo=2 AND status=2";
$query = mysql_query($prestamosTotal2, $tecno) or die(mysql_error());
$row_prestamosTotal2= mysql_fetch_assoc($query);
$totalRows_prestamosTotal2 = mysql_num_rows($query);


$prestamos = "SELECT SUM(monto)- SUM(abono) as totalCuotasPend FROM detallescliente WHERE tipo=2 AND status IN (0,2)";
$query = mysql_query($prestamos, $tecno) or die(mysql_error());
$row_prestamos= mysql_fetch_assoc($query);
$totalRows_prestamos = mysql_num_rows($query);

$productos = "SELECT SUM(monto)- SUM(abono) as totalCuotasPend FROM detallescliente WHERE tipo=1 AND status IN (0,2)";
$query = mysql_query($productos, $tecno) or die(mysql_error());
$row_productos= mysql_fetch_assoc($query);
$totalRows_productos = mysql_num_rows($query);


$productos2 = "SELECT SUM(monto) as total FROM detallescliente WHERE tipo=1";
$query = mysql_query($productos2, $tecno) or die(mysql_error());
$row_productos2= mysql_fetch_assoc($query);
$totalRows_productos2 = mysql_num_rows($query);



$capital = "SELECT SUM(cantidad) as total FROM pagos, detallescliente WHERE pagos.tipo=0 AND pagos.status=0 AND pagos.idArt=detallescliente.idArt AND detallescliente.tipo=3";
$query = mysql_query($capital, $tecno) or die(mysql_error());
$row_capital= mysql_fetch_assoc($query);
$totalRows_capital = mysql_num_rows($query);

?>
<div id="detalleTotal" style="height:auto; min-height:225px;">
  <table cellspacing="3" width="650px">
    <tr>
      <td colspan="6" class='ui-widget-header'>Prestamos</td>
    </tr>
    <tr>
      <td align="center" class='tituloTabla'>Int. Cobrados</td>
      <td align="center" class='tituloTabla'> Int. por Cobrar</td>
      <td align="center" class='tituloTabla'>Capital por Cobrar</td>
      <td align="center" class='tituloTabla'>Capital Cobrado</td>
    </tr>
    <tr class="rowTabla" style="text-align:center;">
      <td><?php echo round($row_prestamosTotal['totalCuotasPagadas']+$row_prestamosTotal2['totalCuotasAbonadas'],2);?></td>
      <td><?php echo round($row_prestamos['totalCuotasPend'],2); ?></td>
      <td><?php echo round($row_prestamosAll['porcobrar'],2); ?></td>
      <td><?php echo round($row_prestamosAll['cobrado'],2); ?></td>
      </tr>
    <tr>
      <td colspan="6" class='ui-widget-header'>Total Prestado: &nbsp;<?php echo " ".round($row_prestamosAll['total'],2)." Bs."; ?></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <table cellspacing="3" width="650px">
    <tr>
      <td colspan="4" class='ui-widget-header'>Productos</td>
    </tr>
    <tr>
      <td width="277" align="center" class='tituloTabla'>Pend. por Cobrar</td>
      <td width="358" align="center" class='tituloTabla'> Cobrados</td>
    </tr>
    <tr class="rowTabla" style="text-align:center;">
      <td><?php echo round($row_productos['totalCuotasPend'],2);?></td>
      <td><?php echo round($row_productos2['total']-$row_productos['totalCuotasPend'],2); ?></td>
      </tr>
    <tr>
      <td colspan="4" class='ui-widget-header'>Total Productos Vendidos: &nbsp;<?php echo " ".round( $row_productos2['total'],2)." Bs."; ?></td>
    </tr>
  </table>
</div>